package com.cbx.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.ObjectDao;
import com.pro.bean.Info;
import com.pro.bean.Mark;
import com.pro.bean.Users;

public class showServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public showServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
	
		
		
	int cardid=Integer.parseInt(request.getParameter("cardid"));
		
		ObjectDao ssa =new ObjectDao();
		List markrs = ssa.find(cardid, new Mark());
		List infors = ssa.find(cardid, new Info());
		Info in = (Info)infors.get(0);
		Mark mm = (Mark)markrs.get(0);
		
		if(mm.getOwuserid() == ((Users)request.getSession().getAttribute("Users")).getUserid())
			request.setAttribute("mode", 1);
		else
			request.setAttribute("mode", 2);//cannot edit
		
		request.getSession().setAttribute("txtComJNam", in.getCmp());
		request.getSession().setAttribute("txtComJNampy", in.getCmpPinYin());
		request.getSession().setAttribute("txtComJNameng",in.getCmpEng());
		request.getSession().setAttribute("txtComunit", in.getDept());
		request.getSession().setAttribute("txtComcaree", in.getPost());
		request.getSession().setAttribute("txtComname", in.getFirstName());
		request.getSession().setAttribute("txtComnamepy", in.getFirstNamePY());
	
		
		
		request.getSession().setAttribute("zip1", in.getZipCode1());
		request.getSession().setAttribute("zipprovince1", in.getProvince1());
		request.getSession().setAttribute("zipcity1", in.getCity1());
		request.getSession().setAttribute("zipzone1", in.getRegion1());
		request.getSession().setAttribute("zipaddress1", in.getAddress1());
		request.getSession().setAttribute("zipphone1", in.getTelFirst1());
		request.getSession().setAttribute("zipphone2", in.getTelSecond1());
		request.getSession().setAttribute("zipmobile1", in.getMobileTel1());
		request.getSession().setAttribute("zipfax1",in.getFax1());
		request.getSession().setAttribute("zipemail1", in.getEmail1());
		request.getSession().setAttribute("zipurl1", in.getUrl1());
		
		request.getSession().setAttribute("zip2", in.getZipCode2());
		request.getSession().setAttribute("zipprovince2", in.getProvince2());
		request.getSession().setAttribute("zipcity2", in.getCity2());
		request.getSession().setAttribute("zipzone2", in.getRegion2());
		request.getSession().setAttribute("zipaddress2", in.getAddress2());
		request.getSession().setAttribute("ziptelphone1", in.getTelFirst2());
		request.getSession().setAttribute("ziptelphone2", in.getTelSecond2());
		request.getSession().setAttribute("zipmobile2", in.getMobileTel2());
		request.getSession().setAttribute("zipfax2",in.getFax2());
		request.getSession().setAttribute("zipemail2", in.getEmail2());
		request.getSession().setAttribute("zipurl2", in.getUrl2());
		
	
		
		
		request.getSession().setAttribute("ddlstPublic", mm.getIspublic());
		request.getSession().setAttribute("ddlstImptantKub", in.getImportant());
		request.getSession().setAttribute("ddlstRelationKub", in.getRelation());
		request.getSession().setAttribute("ddlstJobKub", in.getJob());
		request.getSession().setAttribute("ddlstSexKub", in.getSex());
		request.getSession().setAttribute("ddlstBlodKub", in.getBlood());
		request.getSession().setAttribute("birthday", in.getBirthday());
		request.getSession().setAttribute("txtMemo", in.getMemo());
		request.getSession().setAttribute("industry", in.getBusiness());
		request.getSession().setAttribute("establish", in.getCmpFdDate());
		request.getSession().setAttribute("funding", in.getCapital());
		request.getSession().setAttribute("staff", in.getEmpNum());
		request.getSession().setAttribute("security", in.getBondCode());
		request.getSession().setAttribute("corporate", in.getRepName());
		//request.setAttribute("mode", 1);
		request.getSession().setAttribute("img1", mm.getCardfront());
		request.getSession().setAttribute("img2", mm.getCardback());

		request.getSession().setAttribute("cardid", cardid);
		RequestDispatcher dispatcher=request.getRequestDispatcher("../cbxpage/addcart.jsp");
		dispatcher.forward(request, response);
		
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
